package com.ruoyi.project.system.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysPerson;
import com.ruoyi.project.system.service.ISysPersonService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 员工Controller
 *
 * @author theme
 * @date 2020-06-24
 */
@Api(description = "员工Controller")
@RestController
@RequestMapping("/system/person")
public class SysPersonController extends BaseController {
    @Autowired
    private ISysPersonService sysPersonService;

/**
 * 查询员工列表
 */
@ApiOperation("查询员工列表")
@PreAuthorize("@ss.hasPermi('system:person:list')")
@GetMapping("/list")
        public TableDataInfo list(SysPerson sysPerson) {
        startPage();
        List<SysPerson> list = sysPersonService.selectSysPersonList(sysPerson);
        return getDataTable(list);
    }
    
    /**
     * 获取员工详细信息
     */
    @ApiOperation("获取员工详细信息")
    @PreAuthorize("@ss.hasPermi('system:person:query')")
    @GetMapping(value = "/{personId}")
    public AjaxResult getInfo(@PathVariable("personId") Long personId) {
        return AjaxResult.success(sysPersonService.selectSysPersonById(personId));
    }

    /**
     * 新增员工
     */
    @ApiOperation("新增员工")
    @PreAuthorize("@ss.hasPermi('system:person:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPerson sysPerson) {
        sysPerson.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
        return toAjax(sysPersonService.insertSysPerson(sysPerson));
    }

    /**
     * 修改员工
     */
    @ApiOperation("修改员工")
    @PreAuthorize("@ss.hasPermi('system:person:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPerson sysPerson) {
        return toAjax(sysPersonService.updateSysPerson(sysPerson));
    }

    /**
     * 删除员工
     */
    @ApiOperation("删除员工")
    @PreAuthorize("@ss.hasPermi('system:person:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/{personId}")
    public AjaxResult remove(@PathVariable("personId") Long personId) {
        return toAjax(sysPersonService.deleteSysPersonById(personId));
    }

    /**
     * 查询该店铺下的员工列表
     */
    @ApiOperation("查询所有员工列表")
    @PreAuthorize("@ss.hasPermi('system:person:queryList')")
    @GetMapping("/queryList")
    public TableDataInfo queryList(SysPerson sysPerson) {
        startPage();
        List<SysPerson> list = sysPersonService.queryList(sysPerson);
        return getDataTable(list);
    }

}
